home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / c++ / filebuf.z / filebuf
Encoding:
Text File  |  1998-10-30  |  17.8 KB  |  265 lines

  1.  
  2.  
  3.  
  4. FFFFIIIILLLLEEEEBBBBUUUUFFFF((((3333CCCC++++++++))))                                                    FFFFIIIILLLLEEEEBBBBUUUUFFFF((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      filebuf - buffer for file I/O.
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_iiii_oooo_ssss_tttt_rrrr_eeee_aaaa_mmmm_...._hhhh_>>>>
  13.  
  14.      _tttt_yyyy_pppp_eeee_dddd_eeee_ffff _llll_oooo_nnnn_gggg _ssss_tttt_rrrr_eeee_aaaa_mmmm_oooo_ffff_ffff_,,,, _ssss_tttt_rrrr_eeee_aaaa_mmmm_pppp_oooo_ssss_;;;;
  15.      _cccc_llll_aaaa_ssss_ssss _iiii_oooo_ssss _{{{{
  16.      _pppp_uuuu_bbbb_llll_iiii_cccc_::::
  17.                _eeee_nnnn_uuuu_mmmm      _ssss_eeee_eeee_kkkk______dddd_iiii_rrrr _{{{{ _bbbb_eeee_gggg_,,,, _cccc_uuuu_rrrr_,,,, _eeee_nnnn_dddd _}}}}_;;;;
  18.                _eeee_nnnn_uuuu_mmmm      _oooo_pppp_eeee_nnnn______mmmm_oooo_dddd_eeee _{{{{ _iiii_nnnn_,,,, _oooo_uuuu_tttt_,,,, _aaaa_tttt_eeee_,,,, _aaaa_pppp_pppp_,,,, _tttt_rrrr_uuuu_nnnn_cccc_,,,, _nnnn_oooo_cccc_rrrr_eeee_aaaa_tttt_eeee_,,,, _nnnn_oooo_rrrr_eeee_pppp_llll_aaaa_cccc_eeee _}}}} _;;;;
  19.                _////_//// _aaaa_nnnn_dddd _llll_oooo_tttt_ssss _oooo_ffff _oooo_tttt_hhhh_eeee_rrrr _ssss_tttt_uuuu_ffff_ffff_,,,, _ssss_eeee_eeee _iiii_oooo_ssss_((((_3333_CCCC_++++_++++_)))) _...._...._....
  20.      _}}}} _;;;;
  21.  
  22.      _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ffff_ssss_tttt_rrrr_eeee_aaaa_mmmm_...._hhhh_>>>>
  23.  
  24.      _cccc_llll_aaaa_ssss_ssss _ffff_iiii_llll_eeee_bbbb_uuuu_ffff _:::: _pppp_uuuu_bbbb_llll_iiii_cccc _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff _{{{{
  25.      _pppp_uuuu_bbbb_llll_iiii_cccc_::::
  26.                _ssss_tttt_aaaa_tttt_iiii_cccc _cccc_oooo_nnnn_ssss_tttt _iiii_nnnn_tttt _oooo_pppp_eeee_nnnn_pppp_rrrr_oooo_tttt _;;;; _////_**** _dddd_eeee_ffff_aaaa_uuuu_llll_tttt _pppp_rrrr_oooo_tttt_eeee_cccc_tttt_iiii_oooo_nnnn _ffff_oooo_rrrr _oooo_pppp_eeee_nnnn _****_////
  27.  
  28.                          _ffff_iiii_llll_eeee_bbbb_uuuu_ffff_((((_)))) _;;;;
  29.                          _~~~~_ffff_iiii_llll_eeee_bbbb_uuuu_ffff_((((_)))) _;;;;
  30.                          _ffff_iiii_llll_eeee_bbbb_uuuu_ffff_((((_iiii_nnnn_tttt _dddd_))))_;;;;
  31.                          _ffff_iiii_llll_eeee_bbbb_uuuu_ffff_((((_iiii_nnnn_tttt _dddd_,,,, _cccc_hhhh_aaaa_rrrr_****  _pppp_,,,, _iiii_nnnn_tttt _llll_eeee_nnnn_)))) _;;;;
  32.  
  33.                _ffff_iiii_llll_eeee_bbbb_uuuu_ffff_****  _aaaa_tttt_tttt_aaaa_cccc_hhhh_((((_iiii_nnnn_tttt _dddd_)))) _;;;;
  34.                _ffff_iiii_llll_eeee_bbbb_uuuu_ffff_****  _cccc_llll_oooo_ssss_eeee_((((_))))_;;;;
  35.                _iiii_nnnn_tttt       _ffff_dddd_((((_))))_;;;;
  36.                _iiii_nnnn_tttt       _iiii_ssss______oooo_pppp_eeee_nnnn_((((_))))_;;;;
  37.                _ffff_iiii_llll_eeee_bbbb_uuuu_ffff_****  _oooo_pppp_eeee_nnnn_((((_cccc_hhhh_aaaa_rrrr _****_nnnn_aaaa_mmmm_eeee_,,,, _iiii_nnnn_tttt _oooo_mmmm_oooo_dddd_eeee_,,,, _iiii_nnnn_tttt _pppp_rrrr_oooo_tttt_====_oooo_pppp_eeee_nnnn_pppp_rrrr_oooo_tttt_)))) _;;;;
  38.                _ssss_tttt_rrrr_eeee_aaaa_mmmm_pppp_oooo_ssss _ssss_eeee_eeee_kkkk_oooo_ffff_ffff_((((_ssss_tttt_rrrr_eeee_aaaa_mmmm_oooo_ffff_ffff_,,,, _ssss_eeee_eeee_kkkk______dddd_iiii_rrrr_,,,, _iiii_nnnn_tttt _oooo_mmmm_oooo_dddd_eeee_)))) _;;;;
  39.                _ssss_tttt_rrrr_eeee_aaaa_mmmm_pppp_oooo_ssss _ssss_eeee_eeee_kkkk_pppp_oooo_ssss_((((_ssss_tttt_rrrr_eeee_aaaa_mmmm_pppp_oooo_ssss_,,,, _iiii_nnnn_tttt _oooo_mmmm_oooo_dddd_eeee_)))) _;;;;
  40.                _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_****_ssss_eeee_tttt_bbbb_uuuu_ffff_((((_cccc_hhhh_aaaa_rrrr_**** _pppp_,,,, _iiii_nnnn_tttt _llll_eeee_nnnn_)))) _;;;;
  41.                _iiii_nnnn_tttt       _ssss_yyyy_nnnn_cccc_((((_)))) _;;;;
  42.      _}}}}_;;;;
  43.  
  44. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  45.      _ffff_iiii_llll_eeee_bbbb_uuuu_ffffs specialize _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffffs to use a file as a source or sink of
  46.      characters.  Characters are consumed by doing writes to the file, and are
  47.      produced by doing reads.  When the file is seekable, a _ffff_iiii_llll_eeee_bbbb_uuuu_ffff allows
  48.      seeks.  At least 4 characters of putback are guaranteed.  When the file
  49.      permits reading and writing, the _ffff_iiii_llll_eeee_bbbb_uuuu_ffff permits both storing and
  50.      fetching.  No special action is required between gets and puts (unlike
  51.      stdio).  A _ffff_iiii_llll_eeee_bbbb_uuuu_ffff that is connected to a file descriptor is said to be
  52.      _oooo_pppp_eeee_nnnn.  Files are opened by default with a protection mode of _oooo_pppp_eeee_nnnn_pppp_rrrr_oooo_tttt,
  53.      which is 0644.
  54.  
  55.      The _r_e_s_e_r_v_e _a_r_e_a (or buffer, see _ssss_bbbb_uuuu_ffff_...._pppp_uuuu_bbbb(3C++) and _ssss_bbbb_uuuu_ffff_...._pppp_rrrr_oooo_tttt(3C++)) is
  56.      allocated automatically if one is not specified explicitly with a
  57.      constructor or a call to _ssss_eeee_tttt_bbbb_uuuu_ffff_((((_)))).  _ffff_iiii_llll_eeee_bbbb_uuuu_ffffs can also be made _uuuu_nnnn_bbbb_uuuu_ffff_ffff_eeee_rrrr_eeee_dddd
  58.      with certain arguments to the constructor or _ssss_eeee_tttt_bbbb_uuuu_ffff_((((_)))), in which case a
  59.      system call is made for each character that is read or written.  The _gggg_eeee_tttt
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. FFFFIIIILLLLEEEEBBBBUUUUFFFF((((3333CCCC++++++++))))                                                    FFFFIIIILLLLEEEEBBBBUUUUFFFF((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.      and _pppp_uuuu_tttt pointers into the reserve area are conceptually tied together;
  75.      they behave as a single pointer.  Therefore, the descriptions below refer
  76.      to a single get/put pointer.
  77.  
  78.      In the descriptions below, assume:
  79.      - _f is a _ffff_iiii_llll_eeee_bbbb_uuuu_ffff.
  80.      - _p_f_b is a _ffff_iiii_llll_eeee_bbbb_uuuu_ffff_****.
  81.      - _p_s_b is a _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_****.
  82.      - _i, _d, _l_e_n, and _p_r_o_t are _iiii_nnnn_tttts.
  83.      - _n_a_m_e and _p_t_r are _cccc_hhhh_aaaa_rrrr_****s.
  84.      - _m_o_d_e is an _iiii_nnnn_tttt representing an _oooo_pppp_eeee_nnnn______mmmm_oooo_dddd_eeee.
  85.      - _o_f_f is a _ssss_tttt_rrrr_eeee_aaaa_mmmm_oooo_ffff_ffff.
  86.      - _p and _p_o_s are _ssss_tttt_rrrr_eeee_aaaa_mmmm_pppp_oooo_ssss's.
  87.      - _d_i_r is a _ssss_eeee_eeee_kkkk______dddd_iiii_rrrr.
  88.  
  89.      Constructors:
  90.  
  91.      _ffff_iiii_llll_eeee_bbbb_uuuu_ffff_((((_))))
  92.           Constructs an initially closed _ffff_iiii_llll_eeee_bbbb_uuuu_ffff.
  93.  
  94.      _ffff_iiii_llll_eeee_bbbb_uuuu_ffff_((((_d_))))
  95.           Constructs a _ffff_iiii_llll_eeee_bbbb_uuuu_ffff connected to file descriptor _d.
  96.  
  97.      _ffff_iiii_llll_eeee_bbbb_uuuu_ffff_((((_d_,,,, _p_,,,, _l_e_n_))))
  98.           Constructs a _ffff_iiii_llll_eeee_bbbb_uuuu_ffff connected to file descriptor _d and initialized
  99.           to use the reserve area starting at _p and containing _l_e_n bytes.  If
  100.           _p is null or _l_e_n is zero or less, the _ffff_iiii_llll_eeee_bbbb_uuuu_ffff will be unbuffered.
  101.  
  102.      Members:
  103.  
  104.      _p_f_b_====_f_...._aaaa_tttt_tttt_aaaa_cccc_hhhh_((((_d_))))
  105.           Connects _f to an open file descriptor, _d.  _aaaa_tttt_tttt_aaaa_cccc_hhhh_((((_)))) normally returns
  106.           _&&&&_f, but returns 0 if _f is already open.
  107.  
  108.      _p_f_b_====_f_...._cccc_llll_oooo_ssss_eeee_((((_))))
  109.           Flushes any waiting output, closes the file descriptor, and
  110.           disconnects _f.  Unless an error occurs, _f's error state will be
  111.           cleared.  _cccc_llll_oooo_ssss_eeee_((((_)))) returns _&&&&_f unless errors occur, in which case it
  112.           returns _0000.  Even if errors occur, _cccc_llll_oooo_ssss_eeee_((((_)))) leaves the file descriptor
  113.           and _f closed.
  114.  
  115.      _i_====_f_...._ffff_dddd_((((_))))
  116.           Returns _i, the file descriptor _f is connected to.  If _f is closed, _i
  117.           is _EEEE_OOOO_FFFF.
  118.  
  119.      _i_====_f_...._iiii_ssss______oooo_pppp_eeee_nnnn_((((_))))
  120.           Returns non-zero when _f is connected to a file descriptor, and zero
  121.           otherwise.
  122.  
  123.      _p_f_b_====_f_...._oooo_pppp_eeee_nnnn_((((_n_a_m_e_,,,, _m_o_d_e_,,,, _p_r_o_t_))))
  124.           Opens file _n_a_m_e and connects _f to it.  If the file does not already
  125.           exist, an attempt is made to create it with protection mode _p_r_o_t,
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. FFFFIIIILLLLEEEEBBBBUUUUFFFF((((3333CCCC++++++++))))                                                    FFFFIIIILLLLEEEEBBBBUUUUFFFF((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.           unless _iiii_oooo_ssss_::::_::::_nnnn_oooo_cccc_rrrr_eeee_aaaa_tttt_eeee is specified in _m_o_d_e.  By default, _p_r_o_t is
  141.           _ffff_iiii_llll_eeee_bbbb_uuuu_ffff_::::_::::_oooo_pppp_eeee_nnnn_pppp_rrrr_oooo_tttt, which is 0644.  Failure occurs if _f is already
  142.           open.  _oooo_pppp_eeee_nnnn_((((_)))) normally returns _&&&&_f, but if an error occurs it returns
  143.           0.  The members of _oooo_pppp_eeee_nnnn______mmmm_oooo_dddd_eeee are bits that may be or'ed together.
  144.           (Because the or'ing returns an _iiii_nnnn_tttt, _oooo_pppp_eeee_nnnn_((((_)))) takes an _iiii_nnnn_tttt rather than
  145.           an _oooo_pppp_eeee_nnnn______mmmm_oooo_dddd_eeee argument.)  The meanings of these bits in _m_o_d_e are
  146.           described in detail in _ffff_ssss_tttt_rrrr_eeee_aaaa_mmmm(3C++).
  147.  
  148.      _p_====_f_...._ssss_eeee_eeee_kkkk_oooo_ffff_ffff_((((_o_f_f_,,,, _d_i_r_,,,, _m_o_d_e_))))
  149.           Moves the get/put pointer as designated by _o_f_f and _d_i_r.  It may fail
  150.           if the file that _f is attached to does not support seeking, or if
  151.           the attempted motion is otherwise invalid (such as attempting to
  152.           seek to a position before the beginning of file).  _o_f_f is
  153.           interpreted as a count relative to the place in the file specified
  154.           by _d_i_r as described in _ssss_bbbb_uuuu_ffff_...._pppp_uuuu_bbbb(3C++).  _m_o_d_e is ignored.  _ssss_eeee_eeee_kkkk_oooo_ffff_ffff_((((_))))
  155.           returns _p, the new position, or _EEEE_OOOO_FFFF if a failure occurs.  The
  156.           position of the file after a failure is undefined.
  157.  
  158.      _p_====_f_...._ssss_eeee_eeee_kkkk_pppp_oooo_ssss_((((_p_o_s_,,,, _m_o_d_e_))))
  159.           Moves the file to a position _p_o_s as described in _ssss_bbbb_uuuu_ffff_...._pppp_uuuu_bbbb(3C++).
  160.           _m_o_d_e is ignored.  _ssss_eeee_eeee_kkkk_pppp_oooo_ssss_((((_)))) normally returns _p_o_s, but on failure it
  161.           returns _EEEE_OOOO_FFFF.
  162.  
  163.      _p_s_b_====_f_...._ssss_eeee_tttt_bbbb_uuuu_ffff_((((_p_t_r_,,,, _l_e_n_))))
  164.           Sets up the reserve area as _l_e_n bytes beginning at _p_t_r.  If _p_t_r is
  165.           null or _l_e_n is less than or equal to 0, _f will be unbuffered.
  166.           _ssss_eeee_tttt_bbbb_uuuu_ffff_((((_)))) normally returns _&&&&_f.  However, if _f is open and a buffer
  167.           has been allocated, no changes are made to the reserve area or to
  168.           the buffering status, and _ssss_eeee_tttt_bbbb_uuuu_ffff_((((_)))) returns 0.
  169.  
  170.      _i_====_f_...._ssss_yyyy_nnnn_cccc_((((_))))
  171.           Attempts to force the state of the get/put pointer of _ffff to agree (be
  172.           synchronized) with the state of the file _f_...._ffff_dddd_((((_)))).  This means it may
  173.           write characters to the file if some have been buffered for output
  174.           or attempt to reposition (seek) the file if characters have been
  175.           read and buffered for input.  Normally, _ssss_yyyy_nnnn_cccc_((((_)))) returns 0, but it
  176.           returns _EEEE_OOOO_FFFF if synchronization is not possible.
  177.  
  178.           Sometimes it is necessary to guarantee that certain characters are
  179.           written together.  To do this, the program should use _ssss_eeee_tttt_bbbb_uuuu_ffff_((((_)))) (or a
  180.           constructor) to guarantee that the reserve area is at least as large
  181.           as the number of characters that must be written together.  It can
  182.           then call _ssss_yyyy_nnnn_cccc_((((_)))), then store the characters, then call _ssss_yyyy_nnnn_cccc_((((_)))) again.
  183.  
  184. CCCCAAAAVVVVEEEEAAAATTTTSSSS
  185.      _aaaa_tttt_tttt_aaaa_cccc_hhhh_((((_)))) and the constructors should test if the file descriptor they are
  186.      given is open, but I can't figure out a portable way to do that.
  187.  
  188.      There is no way to force atomic reads.
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. FFFFIIIILLLLEEEEBBBBUUUUFFFF((((3333CCCC++++++++))))                                                    FFFFIIIILLLLEEEEBBBBUUUUFFFF((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.      The UNIX system does not usually report failures of seek (e.g., on a
  207.      tty), so a filebuf does not either.
  208.  
  209. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  210.      _ssss_bbbb_uuuu_ffff_...._pppp_uuuu_bbbb(3C++), _ssss_bbbb_uuuu_ffff_...._pppp_rrrr_oooo_tttt(3C++), and _ffff_ssss_tttt_rrrr_eeee_aaaa_mmmm(3C++).
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.